/*
* @(#)ListDmsPublicRootAction.java
*
* Copyright (c) 2003 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
*/

package com.dcivision.dms.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.dms.dao.DmsDocumentDAObject;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.framework.web.AbstractSearchForm;

/**
 * <p>Class Name:       ListDmsPublicRootAction.java    </p>
 * <p>Description:      The list action class for ListUserRecord.jsp</p>
 *
 *  @author          Rollo Chan
 *  @company         DCIVision Limited
 *  @creation date   19/08/2003
 *  @version         $Revision: 1.6 $
 */
public class ListDmsPublicRootAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.6 $";


  /**
   *  Constructor - Creates a new instance of ListDmsPublicRootAction and define the default listName.
   */
  public ListDmsPublicRootAction() {
    super();
    this.setListName("dmsPublicRootList");
    this.setListFunctionName("getPublicRootList");
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  public String getMajorDAOClassName() {
    return("com.dcivision.dms.dao.DmsRootDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.DMS_PUBLIC_FOLDER);
  }

  public void getListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
   
    // check session store folderTreeParentID is exits 
    DmsDocumentDAObject dmsDao = new DmsDocumentDAObject(this.getSessionContainer(request),this.getConnection(request));
    String folderTreeRootID = (String)request.getSession().getAttribute("publicfolderTreeRootID") ;
    String folderTreeParentID = (String)request.getSession().getAttribute("publicfolderTreeParentID") ;
    if(!Utility.isEmpty(folderTreeRootID) && !Utility.isEmpty(folderTreeParentID)){        
        if(Utility.isEmpty(dmsDao.getDocumentByID(TextUtility.parseIntegerObj(folderTreeParentID),"A"))){
            request.getSession().removeAttribute("publicfolderTreeRootID") ;
            request.getSession().removeAttribute("publicfolderTreeParentID") ;
        } 
                
    }    
    super.getListData(mapping,form,request,response);
  }    
  
  /**
   *  Method deleteListData() - Override the parent function and do nothing.
   *
   *  @param      mapping               ActionMapping from struts
   *  @param      form                  ActionForm from struts
   *  @param      request               HttpServletReuqest
   *  @param      respond               HttpServletRespond
   *  @return     void
   *  @throws     ApplicationException  Throws ApplicationException the deleteion failed
   */
  public void deleteListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    // Do Nothing, it is not allow to delete Public Folder here.
  }

}